//
// Created by xili on 2024/8/4 18:08.
// Go big or go home.
//
#include <vector>

using namespace std;

//差分数组
class Solution {
public:
    vector<int> corpFlightBookings(vector<vector<int>> &bookings, int n) {
        //初始状态为0
        vector<int> ans(n, 0);
        for (auto &item: bookings) {
            ans[item[0] - 1] += item[2];
            if (item[1] < n) {
                ans[item[1]] -= item[2];
            }
        }
        //还原差分数组
        for (int i = 1; i < n; i++) {
            ans[i] += ans[i - 1];
        }
        return ans;
    }
};